﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace Aim2.Ennemy {
    class Hexagon : AnimatedObject {
        static Texture2D spriteTexture;
        float initialX;
        float sinAmplitude;

        public Hexagon(Vector2 Position, float sinAmplitude, float speed, IObjectContainer owner) {
            this.owner = owner;
            Scale = 0.5f;
            Depth = 1f;
            frames = 6;
            framesPerSec = 18;
            this.speed = speed;
            this.sinAmplitude = sinAmplitude;

            if (Position != null) {
                this.Position = Position;
                initialX = Position.X;
            }

            Health = 30f;
            CollisionDamage = 10f;

            animatedSprite = new AnimatedSprite(this, frames, framesPerSec);
        }

        public override void Load(ContentManager Content, Viewport viewport) {
            spriteTexture = Content.Load<Texture2D>("Textures/3x2_hexagon");
            spriteTexture.Name = "Textures/3x2_fireball";

            layout = spriteTexture.Name.GetLayout();
            height = spriteTexture.Height;
            width = spriteTexture.Width;
        }

        public override void Update(float elapsed) {
            Vector2 newPosition = new Vector2();
            newPosition.X = initialX + ((float) Math.Sin(Position.Y / (10f * speed))) * sinAmplitude;
            newPosition.Y = Position.Y + speed;
            Position = newPosition;
            animatedSprite.UpdateFrame(elapsed);

            base.Update(elapsed);
        }

        public override void Draw(SpriteBatch spriteBatch) {
            base.Draw(spriteBatch);
            animatedSprite.DrawFrame(spriteBatch, Position, spriteTexture);
        }

        public override Side Side() {
            return Aim2.Side.Ennemy;
        }
    }
}
